package dao;

import java.util.HashMap;

import org.w3c.dom.Document;

import databean.ItemBean;

import utility.Dom2Str;
import utility.Util_Trading;

public class ReviseItemDAO {
	
	
	private static String message;
	
	public static String getMessage() {
		return message;
	}
	
	public static String reviseItem(ItemBean item) {
		
		HashMap<String, String> data = new HashMap<String, String>();
		
		data.put("ItemID", item.getItemID());
		data.put("Title", item.getTitle());
		data.put("Description", item.getDescription());
		data.put("PictureURL", item.getPictureURL());
		data.put("StartPrice", item.getStartPrice());
		data.put("BuyItNowPrice", item.getBuyItNowPrice());
		Document response = Util_Trading.sendRequest("ReviseItem.txt", data);
		
		System.out.println(Dom2Str.getStringFromDocument(response));
		
		String ack = response.getElementsByTagName("Ack").item(0).getChildNodes().item(0).getNodeValue();
		
		if (ack.equals("Failure")) {
			
			message = response.getElementsByTagName("LongMessage").item(0).getChildNodes().item(0).getNodeValue();
			return null;
			
		} else {
		
			return "success";
			
		}
		
		
	}
}
